package com.fanpan26.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author fanpan26
 */
public class CallableThread implements Callable<String> {
    /**
     * Computes a result, or throws an exception if unable to do so.
     *
     * @return computed result
     * @throws Exception if unable to compute a result
     */
    @Override
    public String call() throws Exception {
        return "panzi";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CallableThread thread = new CallableThread();

        FutureTask<String> futureTask = new FutureTask(thread);
         new Thread(futureTask).start();

         System.out.println(futureTask.get());
         futureTask.cancel(true);
    }
}
